package com.kk.xhr.admin.biz.impl;

import com.kk.xhr.admin.biz.INoteBizService;
import com.kk.xhr.common.ErrorCodeEnum;
import com.kk.xhr.common.exception.BusinessException;
import com.kk.xhr.model.entity.Note;
import com.kk.xhr.model.service.INoteService;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 笔记Biz服务接口实现
 *
 * @author kkmystery
 * @version 1.0 2021/3/21
 * @since 1.0.0
 */
@Service
@RequiredArgsConstructor
public class NoteBizServiceImpl implements INoteBizService {
    private final INoteService noteService;

    @Override
    public List<Note> query(Long userId) {
        return noteService.query(userId);
    }

    @Override
    public long add(Long userId, String content) {
        if (StringUtils.isBlank(content)) {
            throw new BusinessException(ErrorCodeEnum.CONTENT_EMPTY);
        }
        return noteService.add(new Note().withUserId(userId).withContent(content));
    }

    @Override
    public boolean modify(Long id, String content) {
        if (StringUtils.isBlank(content)) {
            throw new BusinessException(ErrorCodeEnum.CONTENT_EMPTY);
        }
        return noteService.modify(new Note().withId(id).withContent(content));
    }

    @Override
    public boolean remove(Long id) {
        return noteService.remove(id);
    }
}
